import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import xss from 'xss';
Vue.prototype.xss = xss;
// import VueAxios from 'vue-axios'

// import xss from 'xss';
// Vue.prototype.xss = xss

import './styles/common.css' // 全局样式
import './styles/animate.min.css' // 预设css3库
import './styles/font/iconfont.css' // 阿里巴巴图标库

// elementUi组件库
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 加载显示
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// swiper组件库
import vueSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css' // npm i swiper@^5.2.0 -s
Vue.use(vueSwiper)
Vue.use(ElementUI, {
  zIndex: 1000
})

//如果设置了代理服务器，访问指向自身端口
// const loca = 'http://124.71.81.168:2105/v1/' //生产环境端口
const loca = 'http://localhost:2108/v1/' //开发环境端口

//配置本地资源指向
Vue.prototype.local = loca;


// 配置请求的根路径
axios.defaults.baseURL = loca

Vue.prototype.$http = axios // this.$http

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  NProgress.start() //显示加载图标
  config.headers.token = sessionStorage.getItem('token') // 给请求头token字段带token值
  return config
})

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  if(response.data && response.data.status !== 200){
  //console.log(response.data.message)
  }
  NProgress.done() //关闭加载图标
  return response
},function(error){
  console.log(error)
})

Vue.config.productionTip = false
new Vue({
  router,
  store,
  mounted() {
    document.dispatchEvent(new Event('render-event'))
  }, // this.$store
  render: h => h(App)
}).$mount('#app')
